import axios from 'axios'
import commonUrl from '../common/js/commonUrl.js'
import { loadVillageId } from '../common/js/cache'
import qs from 'qs'

// 透明治理收入部分的数据
export function getInCome () {
  const url = `${commonUrl.apihost}index.php/home/Govern/getIncome?areasId=${loadVillageId()}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 透明治理支出部分的数据
export function getGoverPay () {
  const url = `${commonUrl.apihost}/index.php/home/Govern/getexpenditure?areasId=${loadVillageId()}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 透明治理汇总部分的数据
export function getGoverAll () {
  const url = `${commonUrl.apihost}/index.php/home/Govern/summary?areasId=${loadVillageId()}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 透明治理明细详情部分数据
export function getLookDetail (type) {
  const url = `${commonUrl.apihost}index.php/home/Govern/Detailed`
  const data = {
    type: type,
    areasId: loadVillageId()
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}
